package com.letou.ls.ui;

import org.apache.table.PreferencesUtils;

import com.letou.ls.R;
import com.letou.ls.uitl.Constant;
import com.letou.ls.uitl.DialogUtils;

import android.app.Activity;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;

/**
 * 菜单关于
 *
 * @author libin
 *
 *         2016年6月13日
 */
public class MenuActivity extends Activity implements OnClickListener {
    
    private ImageButton mScreenSwitchBtn;
    private ImageButton mClearBtn;
    private ImageButton mAboutBtn;
    private ImageButton mMenuColor;
    
    private int currentOrientation;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        currentOrientation =
                getIntent().getIntExtra("orientation", Configuration.ORIENTATION_LANDSCAPE);
        if (currentOrientation == Configuration.ORIENTATION_LANDSCAPE) {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
            setContentView(R.layout.activity_menu_landscape);
        } else {
            setContentView(R.layout.activity_menu_portrait);
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        }


        mScreenSwitchBtn = (ImageButton) findViewById(R.id.menu_Screen_switch);
        mClearBtn = (ImageButton) findViewById(R.id.menu_clear);
        mAboutBtn = (ImageButton) findViewById(R.id.menu_about);
        mMenuColor = (ImageButton) findViewById(R.id.menu_color);
        mScreenSwitchBtn.setOnClickListener(this);
        mClearBtn.setOnClickListener(this);
        mAboutBtn.setOnClickListener(this);
        mMenuColor.setOnClickListener(this);
        
        
    }
    
    @Override
    public void onClick(View arg0) {
        // TODO Auto-generated method stub
        Intent intent = null;
        switch (arg0.getId()) {
            case R.id.menu_color:// 颜色设置
                intent = new Intent(this, CorlorSettingActivity.class);
                // startActivity(intent);
                intent.putExtra("orientation", currentOrientation);
                startActivityForResult(intent, 2);
                break;
            case R.id.menu_Screen_switch:// 综合设置
                intent = new Intent(this, AppSettingActivity.class);
                // startActivity(intent);
                intent.putExtra("orientation", currentOrientation);
                startActivityForResult(intent, 1);
                break;
            case R.id.menu_clear:
                
            	 intent = new Intent(this, RecoverActivity.class);
                 // startActivity(intent);
                 intent.putExtra("orientation", currentOrientation);
                 startActivityForResult(intent, 1);
            	
//                DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
//                    
//                    @Override
//                    public void onClick(DialogInterface arg0, int arg1) {
//                        // TODO Auto-generated method stub
//                        PreferencesUtils.clear(MenuActivity.this);
//                        arg0.dismiss();
//                        // android.os.Process.killProcess(android.os.Process.myPid());
//                        // // 获取PID
//                        // System.exit(0); // 常规java、c#的标准退出法，返回值为0代表正常退出
//                        
//                        Intent intent = new Intent();
//                        intent.putExtra(Constant.PRE_TAG_CURRENT_LTTERY_CODE, "111");
//                        setResult(RESULT_OK, intent);
//                        finish();
//                    }
//                };
//                
//                DialogUtils.showDialog(this, "提示", "您确定要清除登录信息等全部数据吗?", listener);
                break;
            case R.id.menu_about:
                intent = new Intent(this, AboutActivity.class);
                intent.putExtra("orientation", currentOrientation);
                startActivity(intent);
                break;
            
        }
        
    }
    
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        // TODO Auto-generated method stub
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode != 1) {
            return;
        }
        String code = null;
        if (data != null) {
            code = data.getStringExtra(Constant.PRE_TAG_CURRENT_LTTERY_CODE);
        }
        
        if (TextUtils.isEmpty(code)) return;
        Intent intent = new Intent();
        intent.putExtra(Constant.PRE_TAG_CURRENT_LTTERY_CODE, code);
        setResult(RESULT_OK, intent);
        finish();
    }
}
